package com.sgb.kjwl.viewmodel.pick;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.user.PickCompanyEntity;
import com.sgb.kjwl.repository.PickProjectRepertory;
import com.sgb.kjwl.view.ui.fragment.pick.PickCompanyDetailFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class PickCompanyDetailFragmentModel extends BaseViewModel {

    private final PickCompanyDetailFragment fragment;
    private PickProjectRepertory repertory;
    private Map map;

    public PickCompanyDetailFragmentModel(PickCompanyDetailFragment pickCompanyDetailFragment, PickProjectRepertory repertory) {
        fragment = pickCompanyDetailFragment;
        this.repertory = repertory;
    }

    public void getCompanyData(String id) {
       DialogHelper.showProgressDialog(fragment.getContext(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getCompanyDetail(id).enqueue(new Callback<BaseEntity<PickCompanyEntity>>() {
            @Override
            public void onResponse(Call<BaseEntity<PickCompanyEntity>> call, Response<BaseEntity<PickCompanyEntity>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showCompanyData(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<PickCompanyEntity>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }

    public void getCountOfCompanyStoreInfo(String comNo) {
        DialogHelper.showProgressDialog(fragment.getContext(), null, "请求中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().enterpriseWebTenderingTabCount(comNo).enqueue(new Callback<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<PickSelectEntity>>> call, Response<BaseEntity<List<PickSelectEntity>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null || response.body().getState() == null) {
                    return;
                }
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    fragment.showCount(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<PickSelectEntity>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }
}
